package com.example.demo.service.Impl;

import com.example.demo.domain.AnalyseGood;
import com.example.demo.repository.AnalyseMapper;
import com.example.demo.service.AnalyseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AnalyseServiceImpl implements AnalyseService {

    @Autowired
    private AnalyseMapper analyseMapper;

    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public Double getProfitByMonth(String start, String end) {
        Double d=analyseMapper.getProfitByMonth(start,end);
        return d==null?0.00:d;
    }

    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public AnalyseGood getAnalyseGood(Integer gid, String start, String end) {
        AnalyseGood analyseGood=analyseMapper.getAnalyseGood(gid, start, end);
        if (analyseGood==null)
        {
            analyseGood=new AnalyseGood();
            analyseGood.setTotalNum(0);
            analyseGood.setTotalCost(0.00);
            analyseGood.setTotalSell(0.00);
            analyseGood.setTotalProfit(0.00);
        }
        return analyseGood;
    }
}
